package com.ruoyi.storeSource.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.storeSource.domain.StoreSource;
import com.ruoyi.storeSource.service.IStoreSourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店图片视频Controller
 *
 * @author ch
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/storeSource/storeSource")
public class StoreSourceController extends BaseController
{
    @Autowired
    private IStoreSourceService storeSourceService;

    /**
     * 查询门店图片视频列表
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreSource storeSource)
    {
        startPage();
        List<StoreSource> list = storeSourceService.selectStoreSourceList(storeSource);
        return getDataTable(list);
    }

    /**
     * 导出门店图片视频列表
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:export')")
    @Log(title = "门店图片视频", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StoreSource storeSource)
    {
        List<StoreSource> list = storeSourceService.selectStoreSourceList(storeSource);
        ExcelUtil<StoreSource> util = new ExcelUtil<StoreSource>(StoreSource.class);
        return util.exportExcel(list, "门店图片视频数据");
    }

    /**
     * 获取门店图片视频详细信息
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeSourceService.selectStoreSourceById(id));
    }

    /**
     * 新增门店图片视频
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:add')")
    @Log(title = "门店图片视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreSource storeSource)
    {
        return toAjax(storeSourceService.insertStoreSource(storeSource));
    }

    /**
     * 修改门店图片视频
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:edit')")
    @Log(title = "门店图片视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreSource storeSource)
    {
        storeSource.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(storeSourceService.updateStoreSource(storeSource));
    }

    /**
     * 删除门店图片视频
     */
    @PreAuthorize("@ss.hasPermi('storeSource:storeSource:remove')")
    @Log(title = "门店图片视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeSourceService.logicDeleteStoreSource(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
